<?php
//创建 PDO 对象时直接设置数据提取模式FETCH MODE
//$db = new PDO('mysql:host=127.0.0.1;dbname=db3', 'root', '12qwas',
//    [PDO::ATTR_DEFAULT_FETCH_MODE =>PDO::FETCH_ASSOC]);
//$ps=$db->query('select * from students limit 1');
//var_dump($ps->fetch());

//创建 PDO 对象后设置提取模式
//$db = new PDO('mysql:host=127.0.0.1;dbname=db3', 'root', '12qwas');
//$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
//$ps=$db->query('select * from students limit 1');
//var_dump($ps->fetch());

//利用 PDO::query 查询时设置提取模式
//$db = new PDO('mysql:host=127.0.0.1; dbname=db3', 'root', '12qwas');
//$ps = $db->query('select * from students limit 1', PDO::FETCH_ASSOC);
//print_r($ps->fetch());

//利用语句对象进行查询时设置提取模式
//$db = new PDO('mysql:host=127.0.0.1; dbname=db3', 'root', '12qwas');
//$ps = $db->prepare('select * from students where xh=?');
//$ps->setFetchMode(PDO::FETCH_ASSOC);
//$ps->execute(['233110101']);
//print_r($ps->fetch());

//利用语句对象 fetch 数据时设置提取模式
$db = new PDO('mysql:host=127.0.0.1; dbname=db3', 'root', '12qwas');
$ps = $db->prepare('select * from students where xh=?');
$ps->execute(['233110101']);
print_r($ps->fetch(PDO::FETCH_ASSOC));